package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.math.BigInteger;

@Cmd(code = Protocol.C_CROSS_UNION_AFTER_LOGIN, desc = "区服玩家登录")
public class CrossUnionUserLoginCmd extends CrossCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        CrossUnionProto.CrossUnionMemberLoginReqMsg reqMsg = CrossUnionProto.CrossUnionMemberLoginReqMsg.parseFrom(packet.getBytes());

        CrossUserMgr.updateUserBaseInfo(packet.getPlayerId(), PlayerBasePb.parseToUserBaseInfo(reqMsg.getPlayerBaseData()));

        CrossUnionMgr.userLogin(serverId, packet.getPlayerId(), reqMsg.getUnionUid());
        if (reqMsg.hasHistoryMaxAbility()) {
            CrossUnionMgr.checkUserMonthRankGrade(serverId, packet.getPlayerId(), new BigInteger(reqMsg.getHistoryMaxAbility()));
            //同步回游戏服
            CrossUnionMgr.syncGradeBack(serverId,packet.getPlayerId());
        }
    }

    @Override
    public void sendData() {

    }
}
